function [is_lateral,states] = LateralClassifier( accel,is_lateral,states )
%   detact lateral motion

%-------------------------TUNNING FACTORS---------------------------------
Threshold=0.6; % Lateral acceleration threshold
Buffer=10;     % To Prevent frequenct changin of states 
%-------------------------------------------------------------------------

buffer_counter=states(1);
average=states(2);

%Recursive Average Filter
[ average ] = LowPassFilter( average,accel,0.995 );

%-------------Finite State Machine ----------------------------------------
 switch is_lateral
         case false % Longitudinal Motion
                if abs(accel-average)>Threshold
                    is_lateral= true;
                end

         case true  % Lateral Motion
             if abs(accel-average)<Threshold
                 buffer_counter=buffer_counter+1;
                 if buffer_counter>Buffer
                    is_lateral= false;
                    buffer_counter=0;
                 end
             else
                 buffer_counter=0;
             end
 end
 
states=[buffer_counter,average];

end



